package model;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import factory.HibernateUtil;


public class PerfilDao {
	
	public static List<Perfil> buscarTodos() {
		List<Perfil> perfis = new ArrayList<Perfil>();
		Transaction trns = null;
		Session session = HibernateUtil.getSession();
		try {
			trns = session.beginTransaction();
			perfis = session.createQuery("from Perfil").list();
		} catch (RuntimeException e) {
			e.printStackTrace();
		} finally {
			session.flush();
			session.close();
		}
		return perfis;
	}

	 public static Perfil buscarPorId(String id) {
	        Perfil perfil = new Perfil();
	        Transaction trns = null;
	        Session session = HibernateUtil.getSession();
	        Query query = session.createQuery("from Perfil where idPerfil = "+ id);
	        try {
	            trns = session.beginTransaction();
	            perfil = (Perfil) query.uniqueResult();
	        } catch (RuntimeException e) {
	            e.printStackTrace();
	        } finally {
	            session.flush();
	            session.close();
	        }
	        return perfil;
	    }
}
